<?php
/**
 * Created by PhpStorm.
 * User: zzw
 * Date: 17-3-7
 * Time: 下午2:25
 */
if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Identity_model extends MY_Model {

    protected $table = 'identity';
    // 设定
    public function set($id,$arr)
    {
        $this->db->set($arr)
            -> where(array('id'=>$id))
            -> update($this->table);
        return $this->db->affected_rows();
    }
    public function get_count_all($where=FALSE,$table=FALSE,$join=false){
        if (!$table) {
            $table = $this->table;
        }

        $count = 0;
        if ($where === FALSE) {
            if($join && is_array($join)) {
                $count = $this->db->join($join[0],$join[1],$join[2])->count_all_results($table);
            } else {
                $count  = $this->db->count_all_results($table);
            }

        }else{
            if($join && is_array($join)) {

                $count  = $this->db->join($join[0],$join[1],$join[2])->where($where)->count_all_results($table);

            } else {
                //var_dump($this->db->last_query());die();
                $count  = $this->db->where($where)->count_all_results($table);
            }

        }
        return $count;
    }
    /**
     * 用户未进行审核的数量
     */
    public function get_status_nums(){
        $query = $this->db
            ->select('count(*) as total')
            ->from($this->table)
            ->where('status',0)
            ->get();
        //var_dump($this->db->last_query());die();
        return $query->row_array();
    }
    public function get_one($where, $fields = "*", $table = false) {
        if (!$table) {
            $table = $this->table;
        }
        if (!$where) {
            return false;
        }
        $this->db->select($fields)->from($table);
        if (!is_numeric($where)) {
            $this->db->where($where);
        } else {
            $this->db->where('id', $where);
        }

        $this->db->order_by('id', 'desc');

        // 假删
        //$this->db->where('audit', '1');

        $query = $this->db->get();
        $row = $query->row_array();
        return $row;
    }

}